import Vue from 'vue';
import VueRouter from 'vue-router';
import Layout from '../LayoutView.vue';

Vue.use(VueRouter)

const routes=[
  {
    path: '/',
    // redirect: '/category'
    redirect: '/index'
  },
  {
    path: '/',
    name: 'layout',
    component: Layout,
    children: [
      {
        path: '/index',
        name: 'index',
        component: () => import("../views/HomeView.vue")
      },
      {
        path: 'home',
        name: 'home',
        component: () => import('../views/ExamCategory.vue')
      },
      {
        path: 'my',
        name: 'my',
        component: () => import('../views/MyView.vue')
      },

    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import("../views/LoginView.vue")
  },
  {
    path: '/register',
    name: 'register',
    component: () => import("../views/RegisterView.vue")
  }
  ,
  {
    path: '/category',
    name: 'category',
    component: () => import('../views/ExamCategory.vue')
  }
  ,
  {
    path: '/detail',
    name: 'detail',
    component: () => import('../views/ExamDetail.vue')
  }
  ,
  {
    path: '/test',
    name: 'test',
    component: () => import('../views/TestView.vue')
  }
  ,
  {
    path: '/result',
    name: 'result',
    component: () => import('../views/ExamResult.vue')
  },

]

const router = new VueRouter({
  routes
})

export default router

let originPush = VueRouter.prototype.push;
let originReplace = VueRouter.prototype.replace;
VueRouter.prototype.push = function (location, resolve, reject) {
  if (resolve && reject) {
    originPush.call(this, location, resolve, reject)
  } else {
    originPush.call(this, location, () => { }, () => { })
  }
}
VueRouter.prototype.replace = function (location, resolve, reject) {
  if (resolve && reject) {
    originReplace.call(this, location, resolve, reject)
  } else {
    originReplace.call(this, location, () => { }, () => { })
  }
}

